#include <iostream>
#include <string>
using namespace std;
#include "gtest/gtest.h"
#include "List02.hpp"

TEST(frontTest, constReference)
{
	int arr[] = { 1, 2 };
	const size_t len_arr = sizeof(arr) / sizeof(int);
	List<int> int_list(arr, arr + len_arr);

	EXPECT_EQ(1, int_list.front());

	// string
	const char * str_arr[] = {
		"Hello, ",
		"the ",
		"world"
	};
	const size_t len_str_arr = sizeof(str_arr) / sizeof(const char *);
	List<string> str_list(str_arr, str_arr + len_str_arr);

	EXPECT_STREQ("Hello, ", str_list.front().c_str());



}

TEST(frontTest, null)
{
	List<int> int_list;
	EXPECT_EQ(0u, int_list.size());
	
	EXPECT_THROW(int_list.front(), OutOfRange);
}

TEST(frontTest, reference)
{
	int arr[] = { 1, 2 };
	const size_t len_arr = sizeof(arr) / sizeof(int);
	List<int> int_list(arr, arr + len_arr);
	int_list.front() += 2;

	EXPECT_EQ(3, int_list.front());

	// string
	const char * str_arr[] = {
		"Hello, ",
		"the ",
		"world"
	};
	const size_t len_str_arr = sizeof(str_arr) / sizeof(const char *);
	List<string> str_list(str_arr, str_arr + len_str_arr);

	str_list.front() += "the world";
	EXPECT_STREQ("Hello, the world", str_list.front().c_str());
}

TEST(backTest, constReference)
{
	int arr[] = { 1, 2 };
	const size_t len_arr = sizeof(arr) / sizeof(int);
	List<int> int_list(arr, arr + len_arr);

	EXPECT_EQ(2, int_list.back());

	// string
	const char * str_arr[] = {
		"Hello, ",
		"the ",
		"world"
	};
	const size_t len_str_arr = sizeof(str_arr) / sizeof(const char *);
	List<string> str_list(str_arr, str_arr + len_str_arr);

	EXPECT_STREQ("world", str_list.back().c_str());



}

TEST(backTest, null)
{
	List<int> int_list;
	EXPECT_EQ(0u, int_list.size());
	
	EXPECT_THROW(int_list.back(), OutOfRange);
}

TEST(backTest, reference)
{
	int arr[] = { 1, 2 };
	const size_t len_arr = sizeof(arr) / sizeof(int);
	List<int> int_list(arr, arr + len_arr);
	int_list.back() += 2;

	EXPECT_EQ(4, int_list.back());

	// string
	const char * str_arr[] = {
		"Hello, ",
		"the ",
		"world"
	};
	const size_t len_str_arr = sizeof(str_arr) / sizeof(const char *);
	List<string> str_list(str_arr, str_arr + len_str_arr);

	str_list.back() += "the world";
	EXPECT_STREQ("worldthe world", str_list.back().c_str());
}

TEST(frontTest, pushAndPop)
{
	List<int> int_list;
	
	int_list.push_front(1);
	EXPECT_EQ(1, int_list.front());
	int_list.push_front(2);
	EXPECT_EQ(2, int_list.front());
	EXPECT_EQ(2u, int_list.size());
	int_list.pop_front();
	EXPECT_EQ(1u, int_list.size());
	EXPECT_EQ(1, int_list.front());
	int_list.pop_front();
	EXPECT_THROW(int_list.front(), OutOfRange);
	EXPECT_THROW(int_list.pop_front(), OutOfRange);
}

TEST(backTest, pushAndPop)
{
	List<int> int_list;
	
	int_list.push_back(1);
	EXPECT_EQ(1, int_list.back());
	int_list.push_back(2);
	EXPECT_EQ(2, int_list.back());
	int_list.pop_back();
	EXPECT_EQ(1, int_list.back());
	int_list.pop_back();
	EXPECT_THROW(int_list.back(), OutOfRange);
	EXPECT_THROW(int_list.pop_back(), OutOfRange);
}
